/**
 * Created by wangxiaoqiang on 2017/9/15.
 */
let pid = wxqUI.getUrlParam("pid");

$.get(rootPath+"/category/"+pid,(res)=> {
    if(res.meta.code===200){
        $("#name").val(res.data.name);
        $("#sort_order").val(res.data.sort_order);
        $("#c_desc").val(res.data.c_desc)
    }

});

let updateCategory = (data)=>{
    $.ajax({
        url:rootPath+"/category",
        type:"PUT",
        data:data,
        success: (res)=> {
            if(res.meta.code === 200 ){
                alert("修改成功")
            }else{
                alert(res.meta.code)
            }
        },
        error: (res)=> {
            alert("服务器出错啦--"+res.meta.code)
        }
    })

};

let nv = new NiceValidate([
    {dom:document.querySelector("#name")},
    {dom:document.querySelector("#sort_order")},
    {dom:document.querySelector("#c_desc")},
]);

$("#submit").click(function () {
    let c_info = nv.niceValidate();
    if(c_info){
        c_info.pid = pid;
        updateCategory(c_info)
    }else {
        alert("请检查您填写的信息")
    }
});